﻿namespace zyn_hy_login
{
    using System;
    using System.Data;

    public class Z8_fl
    {
        private DateTime add_time;
        private string add_user;
        private DataSet dsP;
        private int id;
        private int id2;
        private int id3;
        private string img;
        private string info;
        private string name;
        private string num;
        private string sign;
        private string strP;
        private int type_id;
        private string url;
        private string zt;

        public Z8_fl()
        {
        }

        public Z8_fl(string strId)
        {
            DataRow row = DBCommon.getDataBySql(" select * from z8_fl where id = " + strId).Tables[0].Rows[0];
            this.id = (int) row["id"];
            this.id2 = (int) row["id2"];
            this.id3 = (int) row["id3"];
            this.name = row["name"].ToString().Trim();
            this.num = row["num"].ToString().Trim();
            this.info = row["info"].ToString().Trim();
            this.zt = row["zt"].ToString().Trim();
            this.img = row["img"].ToString().Trim();
            this.url = row["url"].ToString().Trim();
            this.sign = row["sign"].ToString().Trim();
            this.add_time = (DateTime) row["add_time"];
            this.add_user = row["add_user"].ToString().Trim();
            this.type_id = (int) row["type_id"];
        }

        public int DelData(string strid)
        {
            string strSql = "delete z8_fl where id = ";
            strSql = strSql + " '" + strid + "'";
            try
            {
                DBCommon.excuteSql(strSql);
            }
            catch
            {
                return 0;
            }
            return 1;
        }

        public string getMaxId(string strsign)
        {
            string strSql;
            string s;
            if (strsign == "sys")
            {
                strSql = " select max(id) as mid from z8_fl where id<10000 ";
            }
            else
            {
                strSql = " select max(id) as mid from z8_fl ";
            }
            DataRow row = DBCommon.getDataBySql(strSql).Tables[0].Rows[0];
            if (row["mid"] != null)
            {
                s = row["mid"].ToString().Trim();
            }
            else
            {
                s = "0";
            }
            if ((strsign != "sys") && (int.Parse(s) < 0x2710))
            {
                s = "10000";
            }
            int num = int.Parse(s) + 1;
            return num.ToString();
        }

        public string getName(string strId)
        {
            DataRow row = DBCommon.getDataBySql(" select name from z8_fl where id = " + strId).Tables[0].Rows[0];
            return row["name"].ToString().Trim();
        }

        public int getNameCount(string pid, string cname, string zt)
        {
            return DBCommon.excuteSqlCount(" select * from z8_fl where name='" + cname + "'and zt='" + zt + "' and id2=" + pid);
        }

        private void getParentes(string strId)
        {
            if (strId != "0")
            {
                DataRow row = this.dsP.Tables[0].Select("id=" + strId)[0];
                this.strP = row["name"].ToString().Trim() + "/" + this.strP;
                string text = row["id2"].ToString().Trim();
                this.getParentes(text);
            }
        }

        public string getParentId(string strId)
        {
            DataRow row = DBCommon.getDataBySql(" select id2 from z8_fl where id = " + strId).Tables[0].Rows[0];
            return row["id2"].ToString().Trim();
        }

        public string getParentString(string strId)
        {
            string strSql = " select * from z8_fl ";
            this.dsP = DBCommon.getDataBySql(strSql);
            this.getParentes(strId);
            this.strP = "总根/" + this.strP;
            return this.strP;
        }

        public int InsertData()
        {
            object obj2 = ((((((((((("insert into z8_fl(id,id2,id3,name,num,info,zt,img,url,sign,add_time,add_user,type_id) values( " + " " + this.id.ToString() + ",") + " " + this.id2.ToString() + ",") + " " + this.id3.ToString() + ",") + " '" + this.name + "',") + " '" + this.num + "',") + " '" + this.info + "',") + " '" + this.zt + "',") + " '" + this.img + "',") + " '" + this.url + "',") + " '" + this.sign + "',") + " '" + this.add_time.ToString("yyyy/MM/dd hh:mm:ss") + "',") + " '" + this.add_user + "',";
            string strSql = string.Concat(new object[] { obj2, " '", this.type_id, "' )" });
            try
            {
                DBCommon.excuteSql(strSql);
            }
            catch
            {
                return 0;
            }
            return 1;
        }

        public int UpdateData()
        {
            object obj2 = ((((((((((" update z8_fl set " + "id2 = " + this.id2.ToString() + ",") + "id3 = " + this.id3.ToString() + ",") + "name = '" + this.name + "',") + "num = '" + this.num + "',") + "info = '" + this.info + "',") + "zt = '" + this.zt + "',") + "img = '" + this.img + "',") + "url = '" + this.url + "',") + "sign = '" + this.sign + "',") + "add_time = '" + this.add_time.ToString("yyyy/MM/dd hh:mm:ss") + "',") + "add_user= '" + this.add_user + "', ";
            object obj3 = string.Concat(new object[] { obj2, "type_id= ", this.type_id, " " });
            string strSql = string.Concat(new object[] { obj3, "where id = ", this.id, "" });
            try
            {
                DBCommon.excuteSql(strSql);
            }
            catch
            {
                return 0;
            }
            return 1;
        }

        public DateTime Add_time
        {
            get
            {
                return this.add_time;
            }
            set
            {
                this.add_time = value;
            }
        }

        public string Add_user
        {
            get
            {
                return this.add_user;
            }
            set
            {
                this.add_user = value;
            }
        }

        public int Id
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        public int Id2
        {
            get
            {
                return this.id2;
            }
            set
            {
                this.id2 = value;
            }
        }

        public int Id3
        {
            get
            {
                return this.id3;
            }
            set
            {
                this.id3 = value;
            }
        }

        public string Img
        {
            get
            {
                return this.img;
            }
            set
            {
                this.img = value;
            }
        }

        public string Info
        {
            get
            {
                return this.info;
            }
            set
            {
                this.info = value;
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        public string Num
        {
            get
            {
                return this.num;
            }
            set
            {
                this.num = value;
            }
        }

        public string Sign
        {
            get
            {
                return this.sign;
            }
            set
            {
                this.sign = value;
            }
        }

        public int Type_id
        {
            get
            {
                return this.type_id;
            }
            set
            {
                this.type_id = value;
            }
        }

        public string Url
        {
            get
            {
                return this.url;
            }
            set
            {
                this.url = value;
            }
        }

        public string Zt
        {
            get
            {
                return this.zt;
            }
            set
            {
                this.zt = value;
            }
        }
    }
}

